package com.blt.car.me;

import android.widget.ListView;

import com.blt.car.R;
import com.blt.car.base.BaseTitleBarActivity;
import com.blt.car.base.ViewHolder;
import com.blt.car.me.adapter.ComplaintAdapter;
import com.chanven.lib.cptr.PtrClassicFrameLayout;
import com.chanven.lib.cptr.PtrDefaultHandler;
import com.chanven.lib.cptr.PtrFrameLayout;
import com.chanven.lib.cptr.loadmore.OnLoadMoreListener;

import java.util.List;

import blt.app_core.api.base.CoreEvent;
import blt.app_core.api.base.CoreManager;
import blt.app_core.api.journey.JourneyApi;
import blt.app_core.api.journey.bean.AppealInfo;
import blt.app_core.api.message.MessageApi;

/**
 * Created by xgp on 2017/6/20.
 */

public class MyComplainActivity extends BaseTitleBarActivity {
    private ListView mListview;
    private ComplaintAdapter adapter;
    private PtrClassicFrameLayout frameLayout;
    private int page=1;
    private int pageSize = 15;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_complain;
    }

    @Override
    protected void initData() {
        super.initData();
        CoreManager.getCore(JourneyApi.class).getAppeal(page, pageSize);
    }

    @Override
    protected void initView(ViewHolder holder) {
        mTitleBar.setTitle("我的申诉");
        mListview = holder.get(R.id.complaint_listview);
        adapter = new ComplaintAdapter(this);
        mListview.setAdapter(adapter);
        frameLayout = holder.get(R.id.complaint_frame);
        frameLayout.setLoadMoreEnable(true);
        frameLayout.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                page = 1;
                CoreManager.getCore(JourneyApi.class).getAppeal(page, pageSize);
            }
        });
        frameLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void loadMore() {
                page++;
                CoreManager.getCore(JourneyApi.class).getAppeal(page, pageSize);
            }
        });

    }

    @CoreEvent(coreClientClass = JourneyApi.class)
    public void onComplaint(List<AppealInfo> data){
        if (page == 1) {
            adapter.clear();
            frameLayout.refreshComplete();
        } else {
            frameLayout.loadMoreComplete(true);
        }
        adapter.addData(data);
    }
}
